/*
 * @Description: 分组排序相关规则
 * @Author: Rfan
 * @Date: 2022-10-31 10:56:57
 * @LastEditTime: 2022-10-31 17:40:05
 */

import { configRequest } from '@/utils/request';
import { ICoordinate } from '@/interfaces/global';
import { IRepo } from '@/interfaces/archiveType';

export function fetchGroupSortRule(data: ICoordinate) {
  return configRequest({
    url: `/group-sort-rule/rule`,
    method: 'post',
    data
  });
}

export interface addGroupSortRuleParams extends ICoordinate {
  groupFieldList: IGroupFieldList;
  serialLength: string;
  sortFieldList: ISortFieldList[];
  triggerMode: ITriggerMode;
  remark: string;
}

export interface GroupFieldItem {
  fieldId: number;
  required: boolean;
  sortNo: number;
}

export type IGroupFieldList = GroupFieldItem[];

export interface ISortFieldList {
  fieldId: number;
  sortNo: number;
  sortType: number;
}

export interface ITriggerMode<T = IRepo> {
  autoTrigger: boolean;
  dbList: T[];
  manualInput: boolean;
  manualTrigger: boolean;
}

export function addGroupSortRule(data: addGroupSortRuleParams) {
  return configRequest({
    url: `/group-sort-rule/`,
    method: 'post',
    data
  });
}

export interface IGroupSortRule extends addGroupSortRuleParams {
  id: number;
}

export function editGroupSortRule(data: IGroupSortRule) {
  return configRequest({
    url: `/group-sort-rule/`,
    method: 'put',
    data
  });
}
